src/loadso/haiku/SDL_sysloadso.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 29 Oct 2014 20:20:47 +0100
changeset 9201 21d9f9babb30
parent 8149 681eb46b8ac4
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Fixed bug 2647 - Memory leak in SDL_AddHintCallback function - SDL_hints.c

Nitz

Variable entry going out of scope leaks the storage it points to, at:

/* Need to add a hint entry for this watcher */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) {
return;
}

Patch is attached.
slouken@1361
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@1361
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1361
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1361
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1361
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@1361
    22
icculus@7981
    23
#ifdef SDL_LOADSO_HAIKU
slouken@1635
    24
slouken@1361
    25
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
slouken@1361
    26
/* System dependent library loading routines                           */
slouken@1361
    27
slouken@1361
    28
#include <stdio.h>
icculus@7981
    29
#include <os/kernel/image.h>
slouken@1361
    30
slouken@1361
    31
#include "SDL_loadso.h"
slouken@1361
    32
slouken@1895
    33
void *
slouken@1895
    34
SDL_LoadObject(const char *sofile)
slouken@1361
    35
{
slouken@1895
    36
    void *handle = NULL;
slouken@1895
    37
    image_id library_id = load_add_on(sofile);
icculus@2069
    38
    if (library_id < 0) {
icculus@2069
    39
        SDL_SetError(strerror((int) library_id));
slouken@1895
    40
    } else {
slouken@1895
    41
        handle = (void *) (library_id);
slouken@1895
    42
    }
slouken@1895
    43
    return (handle);
slouken@1361
    44
}
slouken@1361
    45
slouken@1895
    46
void *
slouken@1895
    47
SDL_LoadFunction(void *handle, const char *name)
slouken@1361
    48
{
icculus@2069
    49
    void *sym = NULL;
slouken@1895
    50
    image_id library_id = (image_id) handle;
slouken@2120
    51
    status_t rc =
slouken@2120
    52
        get_image_symbol(library_id, name, B_SYMBOL_TYPE_TEXT, &sym);
icculus@2069
    53
    if (rc != B_NO_ERROR) {
icculus@2069
    54
        SDL_SetError(strerror(rc));
slouken@1895
    55
    }
icculus@2069
    56
    return (sym);
slouken@1361
    57
}
slouken@1361
    58
slouken@1895
    59
void
slouken@1895
    60
SDL_UnloadObject(void *handle)
slouken@1361
    61
{
slouken@1895
    62
    image_id library_id;
slouken@1895
    63
    if (handle != NULL) {
slouken@1895
    64
        library_id = (image_id) handle;
slouken@1895
    65
        unload_add_on(library_id);
slouken@1895
    66
    }
slouken@1361
    67
}
slouken@1361
    68
icculus@7981
    69
#endif /* SDL_LOADSO_HAIKU */
icculus@2069
    70
slouken@1895
    71
/* vi: set ts=4 sw=4 expandtab: */